package action;

import entity.User;
import framework.mvc.annotation.Action;
import framework.mvc.annotation.Controller;
import framework.mvc.annotation.Result;
import framework.mvc.enu.ResultType;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@Action(path="/user")
public class UserAction {


    @Action(path = "/login",results = {
            @Result(name = "success",path = "/showSuccess",type = ResultType.REDIRECT),
            @Result(name = "fail",path = "/WEB-INF/login.jsp",type = ResultType.FORWARD)
    })
    public String login(HttpServletRequest request, HttpServletResponse response){
        System.out.println("UserAction.login()");

        if("abc".equals(request.getParameter("username"))&&"123".equals(request.getParameter("password"))){
            return "success";
        }

        return "fail";
    }

    @Action(path = "/getUser",results = @Result(type = ResultType.JSON))
    public User getUser(HttpServletRequest request,HttpServletResponse response){
        System.out.println("UserAction.getUser()");

        User user=new User();
        user.setId(1);
        user.setUsername("abc");
        user.setPassword("123");
        user.setPhone("123456789");

        return user;
    }

    @Action(path = "/regist")
    public String regist(HttpServletRequest request, HttpServletResponse response){
        System.out.println("UserAction.regist()");

        // return "success";
        return null;
    }


    public String f(HttpServletRequest request, HttpServletResponse response){
        System.out.println("UserAction.f()");
        return null;
    }






}
